using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;

public partial class Manager_OrderDetail_OrderDetailForMonth : System.Web.UI.Page
{
    clsWebShop cls = new clsWebShop();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["AdminUserID"] == null)
        {
            Response.Write("<script language=javascript>alert('Time is out.');window.open('../Default.aspx','_top');</script>");
            return;
        }
    }
    protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
    {
          string  sDate  = e.Day.Date.ToString("yyyyMMdd");
          string sDay = e.Day.Date.ToString("dd");
          string sNow = DateTime.Now.ToString("yyyyMMdd");
          string sLinkIsSunday, sNormalDay ;


        if(e.Day.IsOtherMonth)
        {
            e.Cell.Controls.Clear();
            e.Cell.BackColor = Color.FromName("DeepSkyBlue");
        }
        else
        {
            if(e.Day.Date.DayOfWeek.ToString() == "0")
            {
                sLinkIsSunday = "<a href='OrderDetail.aspx?CodeID=" + Request.QueryString["CodeID"]+"&sDate=" + sDate + "&eDate=" + sDate + "'><font color='#330066' face='Verdana' style='font-weight:bold'>" + sDay + "</font></a>";
                sNormalDay = "<font color='#330066' face='Verdana' style='font-weight:bold'>" + sDay + "</font>";
            }
            else
            {
                sLinkIsSunday = "<a href='OrderDetail.aspx?CodeID=" + Request.QueryString["CodeID"]+"&sDate=" + sDate + "&eDate=" + sDate + "'><font color='#330066' face='Verdana'>" + sDay + "</font></a>";
                sNormalDay = "<font color='#330066' face='Verdana'>" + sDay + "</font>";
            }
            
            if(e.Day.IsToday == true)
            {
                e.Cell.Font.Bold = true;
                e.Cell.ForeColor = Color.FromName("#330066");
                e.Cell.BackColor = Color.FromName("LightYellow");
            }
            
            int intDayCompare;
            intDayCompare = int.Parse(sDate) - int.Parse(sNow);
            DataSet ds;
            ds = cls.GetData("select count(*) as ReturnCount from dbo.OrderPD where Status='N'  and substring(UpdDate,1,8)='" + sDate + "'         select count(*) as ReturnCount from dbo.OrderPD where Status='Y'  and substring(UpdDate,1,8)='" + sDate + "'   select count(*) as ReturnCount from dbo.OrderPD where Status='S'  and substring(UpdDate,1,8)='" + sDate + "'   select count(*) as ReturnCount from dbo.OrderPD where Status='E'  and substring(UpdDate,1,8)='" + sDate + "'");

            string strNew = ds.Tables[0].Rows[0]["ReturnCount"].ToString();
            string strSign = ds.Tables[1].Rows[0]["ReturnCount"].ToString();
            string strSend = ds.Tables[2].Rows[0]["ReturnCount"].ToString();
            string strEnd = ds.Tables[3].Rows[0]["ReturnCount"].ToString();

            e.Cell.Controls.Clear();
            if (intDayCompare <= 0 && (strNew != "0" || strSign != "0" || strEnd != "0"))
            {
                Table tbl=new Table();
                TableRow tr =new TableRow();
                TableRow tr1 =new TableRow();
                TableCell td= new TableCell();
                TableCell td1 =new TableCell();
                td.Text = sLinkIsSunday;
                td.Width = Unit.Percentage(90);
                td.HorizontalAlign = HorizontalAlign.Center;
                td.VerticalAlign = VerticalAlign.Bottom;
                tr.Cells.Add(td);
                tbl.Rows.Add(tr);
                string str = "<a class='lbl_CountTotalOrder' onmouseover='javascript:this.style.textDecoration =\"underline\"' onmouseout='javascript:this.style.textDecoration=\"none\"' style='text-decoration:none' href='OrderDetail.aspx?sDate=" + sDate + "&eDate=" + sDate + "&sState=N&CodeID=" + Request.QueryString["CodeID"].ToString() + "'><font size='0.5pt'  face='Verdana' color='Blue'>N:</font><font size='0.5pt'  face='Verdana' color='red'>" + strNew + "</font></a> ";
                str += "<a class='lbl_CountTotalOrder' onmouseover='javascript:this.style.textDecoration =\"underline\"' onmouseout='javascript:this.style.textDecoration=\"none\"' style='text-decoration:none'  href='OrderDetail.aspx?sDate=" + sDate + "&eDate=" + sDate + "&sState=Y&CodeID=" + Request.QueryString["CodeID"].ToString() + "'><font size='0.5pt'  face='Verdana' color='Blue'>Y:</font><font size='0.5pt'  face='Verdana' color='red'>" + strSign + "</font></a> ";
                str += "<a class='lbl_CountTotalOrder' onmouseover='javascript:this.style.textDecoration =\"underline\"' onmouseout='javascript:this.style.textDecoration=\"none\"' style='text-decoration:none'  href='OrderDetail.aspx?sDate=" + sDate + "&eDate=" + sDate + "&sState=S&CodeID=" + Request.QueryString["CodeID"].ToString() + "'><font size='0.5pt'  face='Verdana' color='Blue'>S:</font><font size='0.5pt'  face='Verdana' color='red'>" + strSend + "</font></a> ";

                str += "<a class='lbl_CountTotalOrder' onmouseover='javascript:this.style.textDecoration =\"underline\"' onmouseout='javascript:this.style.textDecoration=\"none\"' style='text-decoration:none'  href='OrderDetail.aspx?sDate=" + sDate + "&eDate=" + sDate + "&sState=E&CodeID=" + Request.QueryString["CodeID"].ToString() + "'><font size='0.5pt'  face='Verdana' color='Blue'>E:</font><font size='0.5pt'  face='Verdana' color='red'>" + strEnd + "</font></a>";
                td1.Text = str;
                td1.HorizontalAlign = HorizontalAlign.Center;
                td1.Wrap = false;
                td1.Width = Unit.Percentage(10);
                td1.HorizontalAlign = HorizontalAlign.Left;
                td1.VerticalAlign = VerticalAlign.Bottom;
                tr1.Cells.Add(td1);
                tr1.HorizontalAlign = HorizontalAlign.Left;
                tr1.VerticalAlign = VerticalAlign.Bottom;
                tbl.Rows.Add(tr1);
                tbl.Height = Unit.Percentage(100);
                tbl.Width = Unit.Percentage(100);
                e.Cell.Controls.Add(tbl);
            }
            else
            {
                Table tbl=new Table(); 
                TableRow tr=new TableRow();
                TableRow tr1=new TableRow();
                TableCell td =new TableCell();
                TableCell td1=new TableCell();
                td.Text = sNormalDay;
                td.Width = Unit.Percentage(90);
                td.HorizontalAlign = HorizontalAlign.Center;
                td.VerticalAlign = VerticalAlign.Bottom;
                tr.Cells.Add(td);
                tbl.Rows.Add(tr);

                td1.Text = "&nbsp;";
                td1.Width = Unit.Percentage(10);
                td1.HorizontalAlign = HorizontalAlign.Left;
                td1.VerticalAlign = VerticalAlign.Bottom;
                tr1.Cells.Add(td1);
                tr1.HorizontalAlign = HorizontalAlign.Left;
                tr1.VerticalAlign = VerticalAlign.Bottom;
                tbl.Rows.Add(tr1);
                tbl.Width = Unit.Percentage(100);
                e.Cell.Controls.Add(tbl);

            }
        }
        e.Cell.HorizontalAlign = HorizontalAlign.Center;
        e.Cell.VerticalAlign = VerticalAlign.Bottom;
        e.Cell.Style["padding-left"] = "0";
        e.Cell.Style["padding-right"] = "0";
        e.Cell.Style["padding-bottom"] = "0";
    }
}
